<?php

$this->title = "查看库存";

?>
<style type="text/css">
	body{background-color: #FFFFFF;}
	h3{margin:0;}
	#header{background-color: #01BBBD;padding: 30px;color: #FFFFFF;font-size: 16px;width: 100%}
	#header .title{width: 80%;margin-left: 10%;text-align: center;padding: 5px;}
	#header .title p{color: #FFFFFF;font-size: 18px;margin:0;border-top:1px solid #FFFFFF;border-bottom: 1px solid #FFFFFF;padding:10px;text-shadow: 
		0px 1px 0px #c0c0c0,
		0px 1px 1px rgba(0, 0, 0, 0.6);}
	#header .group{text-align: center;}
	#header .group p{color: #FFFFFF;margin:10px 0 0 0;font-size: 14px;}
	#room{width: 100%;background-color: #00A8A9;padding: 5px;}
	#room .num p{color: #FFFFFF;font-size: 14px;text-align: center;margin:5px 0;}
	#room .num .box:after{position: absolute;left: 0px;top: 0px;bottom:0px;content: '';width: 1px;font-size: 0;background-image: -webkit-linear-gradient(top,rgba(255,255,255,0.1) 0%,rgba(255,255,255,0.5) 50%,rgba(255,255,255,0.1) 100%)}

	#content{background-color: #FFFFFF;} 
	#content .c-title{padding-top: 20px;}
	#content .c-title span{margin:0;color: #333;font-size: 18px;border-bottom: 2px solid #a664a6;
		margin: 15px;padding-bottom: 5px;}
	#content .c-table{margin-top: 20px;}
	#d-tab{width: 100%;}
	#d-tab td{border:1px solid #ddd;text-align:center;font-size: 16px;color: #666;padding: 5px;}
	#d-tab .t-20{width: 20%;}
	#d-tab .t-40{width: 40%;}

	.font-1{font-size: 14px;color:#999;}
	.font-2{color: #333;font-size: 14px;}
	.font-3{color: #999;font-size: 12px;}
	.font-4{font-size: 18px !important;}
	.col-1{color: #9FCE30;}
	.col-2{color: #FC9918;}
	.col-3{color: #FF393A;}
	.col-4{color: #f60 !important;}
	.font_b{color: rgb(41, 167, 226);}

	.bg-col-1{background-color: #9FCE30;height: 10px;float: left;}
	.bg-col-2{background-color: #FC9918;height: 10px;float: left;}
	.bg-col-3{background-color: #FF393A;height: 10px;float: left;}

	.per-bar{text-align: center;padding: 5px;line-height: 33px;}
	.per-bar .bar{width: 80%;border:1px solid #333;height:12px;margin-left: 10%;border-radius: 8px;}
	.per-bar .bar span{display: block;}

	.mui-btn-pink{background-color: #FFFFFF;border:1px solid #a664a6;color: #a664a6;}
	.mui-btn-pink.active{background-color: #a664a6;border:1px solid #a664a6;color: #FFFFFF;}
	.layer-row{margin-top: 10px;}
	.layer-row label{width: 30%;float: left;line-height: 34px;}
	.layer-row input{width: 60%;height: 16px;float: left;}
	.layer-row .box{width: 65%}

	 .layui-m-layercont{padding: 10px 10px;}
	 .mui-btn-sub{background-color: #01BBBD;border:1px solid #01BBBD;color: #FFFFFF;}
	 #SetRoom{margin-right: 20px;}

	 
</style>



<div class="mui-content">

	<input type="hidden" name="user_id" id="user_id" value="<?=\Yii::$app->user->identity->id?>">

	

	<div id="mui-scroll-wrapper" class="mui-scroll-wrapper">
		<div class="mui-scroll">
			<div id="header">
				<div class="title">
					<p><?=$model->name?></p>
				</div>
				<div class="group">
					<p><?=sprintf("团号：%s",$model->code)?></p>
					<p><?=sprintf("%s | %s出发",date("Y年m月d日",strtotime($model->go_time)),yii::$app->params['city'][$model->from_city])?></p>
					
				</div>
			</div>
			
			<?php if(\Yii::$app->user->can('room_create')){?>
			<div id="room">
				<div class="mui-row num">
					<div class="mui-col-xs-3"><p>总数</p><p class="font-4"><?=$stock['total']?></p></div>
					<div class="mui-col-xs-3 box"><p>售出</p><p class="font-4"><?=$stock['sell_num']?></p></div>
					<div class="mui-col-xs-3 box"><p>占位</p><p class="font-4"><?=$stock['occupy_num']?></p></div>
					<div class="mui-col-xs-3 box"><p>剩余</p><p class="font-4"><?=$stock['stock']?></p></div>
				</div>
			</div>
			<?php }?>

			<?php if(\Yii::$app->user->can('room_create')){?>
			<div class="mui-row" style="margin-right:15px;margin-top:5px;">
				<div class="mui-pull-right" id="CreateImgBox">
					<button class="mui-btn mui-btn-warning" data-id="<?=$model->id?>" id="CreateImg">生成图片</button>
				</div>
			</div>

			<form id="SetRoomForm" method="post" action="/front/default/set-room-detail">
				<input type="hidden" value="<?php echo Yii::$app->getRequest()->getCsrfToken(); ?>" name="_csrf" />
				<input type="hidden" name="product_id" value="<?=$model->id?>">
				<input type="hidden" name="data" id="data" value="">
			</form>
			<?php }?>
			<div id="content">
				<div class="c-title">
					<span>出售详情</span>
					<p class="mui-pull-right">
						<?php if(\Yii::$app->user->can('room_create')){?>
						<button class="mui-btn mui-btn-sub" id="SetRoom">占位</button>
						<?php }?>
					</p>
				</div>
				<?php if($model->stock == 1){  //标准库存格式 ?>
				<div class="c-table">
					<table id="d-tab">
						<thead>
							<tr>
								<td class="t-20">类型</td>
								<td class="t-20">人数</td>
								<td class="t-20">价格/同业价格</td>
								<td class="t-20">剩余</td>
								<td class="t-20">操作</td>
							</tr>
						</thead>
						<tbody>
						<?php if(!empty($all_rooms)){?>
							<?php foreach($all_rooms as $rooms){?>
								  
								   	<tr>
										<td class="t-20">
											<?=$rooms->room->name.$rooms->room->code?>
										</td>
										<td class="t-20">
											<?=$rooms->people?>人
										</td>

										<td class="t-20 col-4">
										<?php if(isset($rooms->sell_out) && $rooms->sell_out == 1){ ?>
												 <span>售罄</span>
										<?php }else{ ?>
											<?=(!empty($rooms->price))?sprintf("¥%s",$rooms->price):'--'?><br> 
											<span class="font_b"><?=(!empty($rooms->inside_price))?sprintf("¥%s",$rooms->inside_price):'--'?></span>
										<?php }?>	
										</td>
										<td class="t-20">
										  <?php if(isset($rooms->sell_out) && $rooms->sell_out == 1){ ?>
										  		<span class="col-4">售罄</span>
										  <?php }else{ ?>
										  		<?=($rooms->num-$rooms->stockNum >= 10) ? "9+" : $rooms->num-$rooms->stockNum;?>
										  <?php }?>
										</td>
										<td class="t-20">
										<?php if(\Yii::$app->user->can('room_create')){?>
											<?php if(isset($rooms->sell_out) && $rooms->sell_out == 1){ ?>
											<?php }else{ ?>
												<?php if(($rooms->num-$rooms->stockNum) > 0){?>
												<button class="mui-btn-pink out-set-btn" 
												data-room-num="<?=($rooms->num-$rooms->stockNum)?>"
												data-people-num="<?=$rooms->people?>"
												data-room-name="<?=$rooms->room->name.$rooms->room->code?>"
												data-room-id="<?=$rooms->id?>"
												>

												加入</button>
												<?php }?>	
										<?php } ?>
										<?php }?>			
										</td>
								
										
									</tr>	
									
							<?php }?>
						<?php }?>	
							 	
						</tbody>
					</table>
				</div>
				
				<?php }else if($model->stock == 2){ //自定义库存?> 
				<div class="c-table">
					<table id="d-tab">
						<thead>
							<tr>
								<td class="t-20">类型</td>
								<td class="t-20">第1/2人价格</td>
								<td class="t-20">第3/4人价格</td>
								<td class="t-20">剩余</td>
								<td class="t-20">操作</td>
							</tr>
						</thead>
						<tbody>
						<?php if(!empty($all_rooms)){?>
							<?php foreach($all_rooms as $rooms){?>
								   	<tr>
										<td class="t-20">
											<?=$rooms['name']?>
										</td>
										<td class="t-20 col-4">
										<?php if(isset($rooms['sell_out']) && $rooms['sell_out'] == 1){ ?>
											<span>售罄</span>
										<?php }else{ ?>
											 <?=(!empty($rooms['price']))?sprintf("¥%s",$rooms['price']):'--'?><br>
											<span class="font_b"><?=(!empty($rooms['inside_price']))?sprintf("¥%s",$rooms['inside_price']):'--'?></span>
										<?php }?>		
										</td>
										<td class="t-20 col-4">

										<?php if(isset($rooms['sell_out']) && $rooms['sell_out'] == 1){ ?>		
											<span>售罄</span>
										<?php }else{ ?>
											<?=(!empty($rooms['price2']))?sprintf("¥%s",$rooms['price2']):'--'?><br>
											<span class="font_b"><?=(!empty($rooms['inside_price2']))?sprintf("¥%s",$rooms['inside_price2']):'--'?></span>
										<?php }?>	
															
										</td>
										<td class="t-20">
											<?php if(isset($rooms['sell_out']) && $rooms['sell_out'] == 1){ ?>
												<span class="col-4">售罄</span>	
											<?php }else{ ?>
												<?=($rooms['over_num'] < 10) ? $rooms['over_num'] : "9+"  ?>
											<?php }?>	
										</td>
										<td class="t-20">
										<?php if(\Yii::$app->user->can('room_create')){?>
											<?php if(isset($rooms['sell_out']) && $rooms['sell_out'] == 1){ ?>
											<?php }else{ ?>
												<?php if($rooms['over_num'] > 0){?>
													<button class="mui-btn-pink out-set-btn" 
													data-room-num="<?=$rooms['over_num']?>"
													data-people-num="1"
													data-room-name="<?=$rooms['name']?>"
													data-room-id="<?=$rooms['room_id']?>" >
													加入</button>
												<?php }?>
											<?php }?>	
										<?php }?>		
										</td>
									</tr>
							<?php }?>
						<?php }?>	
							 	
						</tbody>
					</table>
				</div>		
				<?php }?>
			</div>

			

		</div>


	</div>


</div>




<?= yii\web\View::registerJsFile("/js/layer_mobile/layer.js",['depends' => 'app\assets\MuiAsset']) ?>


<?php app\components\JsBlock::begin() ?>

<script type="text/javascript">

mui.init();

mui("body").on('tap','.out-set-btn',function(){
	 var isActive = jQuery(this).hasClass("active");
	 if(isActive){
	 	 jQuery(this).removeClass("active");
	 }else{
	 	 jQuery(this).addClass("active");
	 }
});

mui("body").on('tap','#CreateImg',function(){
	var _self = jQuery(this);
	var id = jQuery(this).attr("data-id");
	jQuery.get("/front/default/create-img",{id:id},function(data) {
		data = jQuery.parseJSON(data);
		if(data.code == 1){
			_self.remove();
			var html = jQuery("<a href='"+data.path+"' class='mui-btn mui-btn-danger'  download='help'>查看图片</a>");
			jQuery("#CreateImgBox").append(html);
		}else{
			alert("error");
		}
	});
	 
});

mui('body').on('tap','a',function(){document.location.href=this.href;});

mui("body").on('tap','#SetRoom',function(){
	var data = [];
	jQuery(".out-set-btn.active").each(function(i){
		var room_num = jQuery(this).attr("data-room-num");	
		var room_id = jQuery(this).attr("data-room-id");
		var people_num = jQuery(this).attr("data-people-num");
		var room_name = jQuery(this).attr("data-room-name");
		data[i] = {"room_name":room_name,"room_id":room_id,"people_num":people_num,"room_num":room_num}; 
	});
	if(jQuery.isEmptyObject(data)){
		mui.toast("至少选一个房间");
		return false;
	}
	data =JSON.stringify(data);
	jQuery("#data").val(data);
	jQuery("#SetRoomForm").submit();

});


mui("#mui-scroll-wrapper").scroll({
	deceleration: 0.0005 
});


</script>

<?php app\components\JsBlock::end() ?>
